package cn.itcast.controller;

import cn.itcast.core.BaseServlet;
import cn.itcast.core.ResponseBody;
import cn.itcast.domain.County;
import cn.itcast.service.CountyService;
import cn.itcast.service.impl.CountyServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.mysql.cj.util.StringUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/CountyController/*")
public class CountyController extends BaseServlet {

    private CountyService countyService = new CountyServiceImpl();

    @ResponseBody
    public Object queryPage(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //1.获取表单数据
        String pageNum = request.getParameter("pageNum");
        if (StringUtil.isEmpty(pageNum)){
            pageNum = "1";
        }

        String pageSize = request.getParameter("pageSize");
        if (StringUtil.isEmpty(pageSize)){
            pageSize = "10";
        }

        PageInfo<County> pageInfo = countyService.queryPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));

        return pageInfo;
    }
}
